import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import 'package:study_flutter/yzhg/dartTools/YEventBusUtil.dart';
import 'package:study_flutter/yzhg/function/eventbus/YEventBusBeanDemo.dart';
import 'package:study_flutter/yzhg/project/shop/content/Content.dart';
import 'package:study_flutter/yzhg/project/shop/event/YEventBusBean.dart';
import 'package:study_flutter/yzhg/project/shop/model/GoodsDetailBean.dart';
import 'package:study_flutter/yzhg/project/shop/pages/shopcar/CartProvide.dart';
import 'package:study_flutter/yzhg/project/shop/provide/GoodsDetailProvide.dart';

class GoodsDetailBottom extends StatefulWidget {
  @override
  _GoodsDetailBottomState createState() => _GoodsDetailBottomState();
}

class _GoodsDetailBottomState extends State<GoodsDetailBottom> {
  @override
  Widget build(BuildContext context) {
    GoodInfo goodInfo = Provide.value<GoodsDetailProvide>(context).goodInfo;
    return Container(
      decoration: BoxDecoration(color: Colors.white),
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(80),
      child: Row(
        children: [
          InkWell(
            onTap: () {},
            child: Container(
              width: ScreenUtil().setWidth(110),
              alignment: Alignment.center,
              child: Icon(
                Icons.shopping_cart,
                size: 35,
                color: Colors.red,
              ),
            ),
          ),
          InkWell(
            onTap: () async {
              await Provide.value<CartProvide>(context).save(goodInfo.goodsId,
                  goodInfo.goodsName, 1, goodInfo.presentPrice, goodInfo.image1);

              /*购物车数据变化了   使用EventBus通知 购物车改变数据*/
              YEventBusUtil.getInstance().fire(YEventBusBean(Content.EVENT_CART_CNAHGE,eventBool: true));
            },
            child: Container(
              alignment: Alignment.center,
              width: ScreenUtil().setWidth(320),
              height: ScreenUtil().setHeight(80),
              color: Colors.green,
              child: Text(
                '加入购物车',
                style: TextStyle(
                    color: Colors.white, fontSize: ScreenUtil().setSp(28)),
              ),
            ),
          ),
          InkWell(
            onTap: () async {
              await Provide.value<CartProvide>(context).remove();
            },
            child: Container(
              alignment: Alignment.center,
              width: ScreenUtil().setWidth(320),
              height: ScreenUtil().setHeight(80),
              child: Text(
                '马上购买',
                style: TextStyle(
                    color: Colors.white, fontSize: ScreenUtil().setSp(28)),
              ),
              color: Colors.red,
            ),
          )
        ],
      ),
    );
  }
}
